/*
 * LoginAS.java
 *
 * Created on August 27, 2007, 9:57 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package tcc.applicationService.login;

import tcc.applicationService.AbstractAS;
import tcc.dao.login.TCCSystemUserDAO;
import tcc.domain.login.TCCSystemUser;

/**
 *
 * @author Diego
 */
public class LoginAS extends AbstractAS{
    
    /** Creates a new instance of LoginAS */
    private LoginAS() {
    }
    private static LoginAS instance;
    
    public static synchronized LoginAS getInstance() {
        if(instance ==null){
            instance = new LoginAS();
        }
        return instance;
    }
    
    public TCCSystemUser canLogin(TCCSystemUser user){
        TCCSystemUserDAO dao =  new TCCSystemUserDAO();
        TCCSystemUser userLoaded = dao.findByLogin(user.getLogin());
        
        if (userLoaded != null && userLoaded.checkPassword(user.getPassword())){
            return userLoaded;
        }else{
            return null;
        } 
        
    }
}
